package @{包路径}.@{功能包名}.controller;

import cn.platform.agent.frame.core.common.ResultBean;
import cn.platform.agent.frame.core.common.ResultBeanHelper;
import cn.platform.agent.frame.core.dao.Page;
import cn.platform.agent.smp.component.ControllerExtend;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

import @{包路径}.@{功能包名}.pojo.@{功能名_大写开头};
import @{包路径}.@{功能包名}.service.I@{功能名_大写开头}Service;

@Controller
@RequestMapping(value = "/@{功能名}")
public class @{功能名_大写开头}Controller extends ControllerExtend {

	private static final Logger logger = LoggerFactory.getLogger(@{功能名_大写开头}Controller.class);

	@Resource
	I@{功能名_大写开头}Service @{功能名}ServiceImpl;

    /**
     * 跳转列表页面
     * @return
     */
    @RequestMapping(value = "/to-list-page", method = RequestMethod.GET)
    public String toListPage() {
        return "list";
    }

    /**
     * 根据UUID查找@{表名}信息
     * @param @{功能名}
     * @return
     */
    @RequestMapping(value = "/find-by-uuid", method = RequestMethod.POST)
    @ResponseBody
    public ResultBean findByUUID(@RequestBody @{功能名_大写开头} @{功能名}) {
        logger.debug("根据UUID查找@{功能名}信息 @{功能名_大写开头}[{}]", @{功能名});
        return this.@{功能名}ServiceImpl.get@{功能名_大写开头}(@{功能名}.getUuid());
    }

    /**
     * 保存@{表名}信息
     * @param @{功能名}
     * @return
     */
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	@ResponseBody
	public ResultBean save(@RequestBody @{功能名_大写开头} @{功能名}) {
        logger.debug("保存@{功能名}信息 @{功能名_大写开头}[{}]", @{功能名});
        return this.@{功能名}ServiceImpl.save(@{功能名});
	}

    /**
    * 将@{表名}置为无效状态
    * @param @{功能名}
    * @return
    */
    @RequestMapping(value = "/lock", method = RequestMethod.POST)
    @ResponseBody
    public ResultBean lock(@RequestBody List<@{功能名_大写开头}> @{功能名}){
        logger.debug("将@{功能名}置为无效状态 @{功能名_大写开头}[{}]", @{功能名});
        return this.@{功能名}ServiceImpl.lock(@{功能名});
    }

    /**
     * 将@{表名}置为有效状态
    * @param @{功能名}
    * @return
    */
    @RequestMapping(value = "/unlock", method = RequestMethod.POST)
    @ResponseBody
    public ResultBean unlock(@RequestBody List<@{功能名_大写开头}> @{功能名}){
        logger.debug("将@{功能名}置为有效状态 @{功能名_大写开头}[{}]", @{功能名});
        return this.@{功能名}ServiceImpl.unlock(@{功能名});
    }

    /**
    * 获取列表数据
    * @param page
    * @return
    */
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	@ResponseBody
	public ResultBean<Page<@{功能名_大写开头}>> find@{功能名_大写开头}ByPage(@RequestBody Page<@{功能名_大写开头}> page) {
		ResultBean<Page<@{功能名_大写开头}>> resultBean = ResultBeanHelper.success(this.@{功能名}ServiceImpl.get@{功能名_大写开头}ByPage(page.getPage(), page.getPageSize(), page.getParams()));
		return resultBean;
	}

}
